from typing import List
from common.enum.strategy_group_enum import StrategyGroup
from common.enum.strategy_type_enum import StrategyType
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_assessment import RiskAssessment
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_stock_day import StrategyStockDay
from service.strategy.base_strategy import BaseStrategy
from service.strategy.base_week_strategy import BaseWeekStrategy

class ThreeDaysCloseNotHighStrategy(BaseStrategy):
    """
    连续3天收盘价是否为当日最高点策略，若不是，根据距离当前天数评分。
    """

    def analyze(self, trade_info_list: List[StrategyStockDay]) -> RiskAssessment:
        """
        分析过去3天内收盘价是否为当日最高点。
        """
        node_point = 0
        description = ""

        # 确保至少有3天的交易数据
        if len(trade_info_list) >= 3:
            # 按天检查收盘价是否为最高价
            for i in range(1, 4):  # 倒数第1天到第3天
                trade_info = trade_info_list[-i]
                if trade_info.close < trade_info.high:
                    # 根据天数分配分数
                    score = 4 - i
                    node_point += score
                    description += f"Day -{i}: Close price ({trade_info.close}) is not the highest ({trade_info.high}), added {score} points. "

            # 如果描述为空，表示所有天数收盘价均为最高价
            if not description:
                description = "过去3天内收盘价均为当日最高点，无异常。"

        # 创建策略信息对象
        return RiskAssessment(
            stock_code=trade_info_list[0].stock_code,
            description=description,
            config=self.strategyConfig(),
            node_point=node_point,
        )

    def strategyConfig(self) -> dict:
        """
        返回策略的配置
        """
        return StrategyInfoMetadata(
            strategy_code="three_days_close_not_high",
            strategy_name="连续3天收盘价非当日最高点策略",
            strategy_group=StrategyGroup.RISK,
            strategy_type=StrategyType.PRICE,
            analysis_day=3,
            strategy_level=2,
        )
